<html>
<head>
    <meta charset="UTF-8">

    <!-- 地址栏显示 -->
    <link rel="Shortcut Icon" href="/static/images/hospital.ico" type="image/x-icon"/>
    <!-- 收藏栏也显示 -->
    <link rel="Bookmark" href="/static/images/hospital.ico" type="image/x-icon"/>

    <link href="/static/sb-admin-2/vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <!-- Custom styles for this template-->
    <link href="/static/sb-admin-2/css/sb-admin-2.css" rel="stylesheet">

    <link href="/static/sb-admin-2/bootstrap/bootstrap-table.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/static/csss/sweetalert.css">

    <title>门诊就诊</title>
    <link rel="stylesheet" type="text/css" href="/static/csss/mcss/mcss_outpatient.css"/>
    <link rel="stylesheet" type="text/css" href="/static/csss/chosen.min.css"/>
    <link type="text/css" rel="stylesheet" href="/static/csss/preloader.css">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/layui/css/layui.css" media="all">
</head>
<body>
<!--正文-->
<div>
    <div class="card shadow mb-4" style="margin-left: 2.5%;height: 818px">

        <div class="card-body">
            <div class="outpatient-div">
                <div class="split split-horizontal" id="outpatient-one">
                    <div class="card-header py-3">
                        <h6 class="m-0 font-weight-bold text-primary">患者基本信息</h6>
                    </div>

                    <div style="margin-left: 5%">
                        <div class="textbox">
                            卡号<input type="text" style="width: 110px" id="cardId">
                            <div class="cardId-search">
                                <button class="btn btn-success" onclick="getCardIdIn(1)">
                                    <img class="png" src="/static/images/icon/search.png">
                                </button>
                            </div>
                        </div>
                        <div class="textbox_2">
                            <div id="new-img" style=" visibility: hidden">
                                <img style="width: 35px;height: 35px;"
                                     src="/static/images/icon/newPatien.png" title="请记录新开卡的病人信息">
                            </div>
                            婚姻<input type="text" id="maritalStatus" style="width: 110px">&emsp;
                            职业<input type="text" id="career" style="width:110px">
                            <input type="text" id="queueId" hidden="hidden"><!--隐藏队列Id-->
                            <br>
                            <br>
                            <br>
                            <div style="display: flex;">
                                <div>个人史</div>
                                <textarea id="personalHistory"></textarea>
                            </div>

                            <div style="display: flex; margin-top: 30px">
                                <div>既往史</div>
                                <textarea type="text" id="pastHistory"></textarea>
                            </div>

                            <div style="display: flex;margin-top: 30px">
                                <div>家族史</div>
                                <textarea type="text" id="familyHistory"></textarea>
                            </div>

                            <div class="mybtn2" id="new-submit">
                                <button class="btn btn-info" onclick="changePatientupdate()">提交修改</button>
                            </div>

                            <div style="display: flex;margin: 20px 0 0 17px;">
                                <div>主诉</div>

                                <textarea id="conditionDescr"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="split split-horizontal" id="outpatient-two">
                    <div>
                        <div class="card-header py-3">
                            <h6 class="m-0 font-weight-bold text-primary">电子处方</h6>
                        </div>

                        <div style="display: flex">
                            <h4 style="font-family: STLiti,serif;color: #2C9FAF">SHOSPITAL</h4>

                            <h2>门诊处方笺</h2>

                            <div style="font-size: 15px;margin-left: 26%">
                                <div id="nowDate"></div>
                            </div>

                        </div>
                        <div class="textbox_3">

                            处方号<input type="text" id="prescriptionNum" name="medicalRecord.tolltakedrug_no" style="width: 170px"
                                      readonly="readonly">
                            科室<input type="text" id="department" style="width: 110px" readonly="readonly">&emsp;
                            日期<input type="text" id="date" style="width: 133px" readonly="readonly">
                            <br> <br>
                            姓名<input type="text" id="name" style="width: 110px" readonly="readonly">&emsp;
                            性别<input type="text" id="sex" style="width: 90px" readonly="readonly">
                            民族<input type="text" id="nationality" style="width: 90px" readonly="readonly">
                            年龄<input type="text" id="age" style="width:90px" readonly="readonly">
                            <br> <br>
                            初步诊断<input type="text" id="diagnosisResult" style="width:505px">
                        </div>

                        <div style="display: flex">
                            <div style="font-size: 1.1rem">
                                <img style="width: 70px;height: 70px"
                                     src="/static/images/icon/prescription.png">
                            </div>
                        </div>
                        <div style="margin: 20px 0 0 185px" id="drugs">
                            <ol>

                            </ol>
                        </div>

                    </div>
                </div>
                <div class="split split-horizontal" id="outpatient-three">
                    <div>
                        <div>
                            <div class="card-header py-3">
                                <h6 class="m-0 font-weight-bold text-primary">身体检查</h6>
                            </div>
                            <div style="width: 100%;margin-top: 20px">
                                <div style="width: 100px">检查结果:</div>
                                <div class="testResult">
                                    体温<input type="text" id="bodyTemperature" style="width: 70px"
                                             readonly="readonly">℃&emsp;
                                    脉搏<input type="text" id="pulse" style="width: 70px"
                                             readonly="readonly">次/分&emsp;
                                    <button class="btn btn-info mybutton"
                                            onclick="findByIdMedicalExamination()">
                                        更新
                                    </button>

                                    <br> <br>
                                    心率<input type="text" id="heartRate" style="width: 70px"
                                             readonly="readonly">次/分&emsp;
                                    血压<input type="text" id="bloodPressure" style="width: 70px"
                                             readonly="readonly">mmHg
                                </div>

                                <br>
                                <div style="margin-left: 300px;">
                                    <button class="btn btn-info mybutton2" onclick="ProcessLater()">
                                        稍后处理
                                    </button>
                                </div>
                            </div>
                            <div>
                                <div class="card-header py-3">
                                    <h6 class="m-0 font-weight-bold text-primary">处方药</h6>
                                </div>
                                <div style="margin-left: 10px">
                                    <div style="display: flex;margin-top: 20px">
                                        <div>
                                            药品:
                                        </div>
                                        <form class="layui-form" action="" lay-filter="edit">
                                        <div style="margin-left: 10px">
                                            <select class='drugSelect' id = "drugSelect" data-placeholder=' '  lay-filter="drugSelect">
                                                <option value=""></option>

                                            </select>
                                        </div>
                                        </form>
                                    </div>
                                    <br>
                                    <!--规格-->
                                    <div style="display: flex;">
                                        <div>
                                            药品规格：
                                        </div>
                                        <div>
                                            <input type="text" id="specification" style="width: 150px"
                                                   readonly="readonly">
                                            <input type="hidden" id="price">
                                        </div>
                                    </div>
                                    <br>
                                    <div style="display: flex">
                                        <div>
                                            用法：
                                        </div>
                                        <div>
                                            <input type="text" style="width: 70px" id="usage">
                                        </div>
                                        <div style="margin-left: 10px">
                                            <select class='drugMethod' data-placeholder=' '>
                                                <option value=""></option>
                                                <option value="口服">口服</option>
                                                <option value="外用">外用</option>
                                            </select>
                                        </div>
                                        <div style="margin-left: 10px">
                                            <select class='drugNum' data-placeholder=' '>
                                                <option value=""></option>
                                                <option value="每日一次">每日一次</option>
                                                <option value="每日两次">每日两次</option>
                                                <option value="每日三次">每日三次</option>
                                            </select>
                                        </div>
                                    </div>

                                    <div style="display: flex;">
                                        <div style="margin: 25px 0 20px 60px; ">
                                            <button class="btn btn-info mybutton" onclick="nullDrugs()">清空
                                            </button>
                                        </div>
                                        <div style="margin: 25px 0 20px 195px; ">
                                            <button class="btn btn-info mybutton" onclick="addDrugs()">添加
                                            </button>
                                        </div>
                                    </div>
                                </div>

                                <div class="card-header py-3">
                                    <h6 class="m-0 font-weight-bold text-primary">医嘱</h6>
                                </div>

                                <div style="display: flex;margin-top: 20px">
                                    <div>
                                        添加医嘱：
                                    </div>
                                    <textarea id="medicalOrder"
                                              style="height: 80px;width: 260px" maxlength="15"></textarea>
                                </div>

                                <div style="margin: 25px 0 20px 290px; ">
                                    <button class="btn btn-info mybutton2" onclick="addMedicalRecord()">门诊完成
                                    </button>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
            <!--队列-->
            <button class="showbar"></button>
            <div class="widget-bar">
                <div style="display: flex;">
                    <h3>患者队列</h3>
                    <button style="margin-left: 115px;margin-top: 7px" class="btn btn-info" title="刷新"
                            onclick="refreshQueue()">
                        <i class="fa fa-sync"></i>
                    </button>
                </div>

                <!--稍后处理的就诊病人-->
                <div id="allPatientLater">
                    <table id="alloutpatientqueue">

                    </table>
                </div>
            </div>

        </div>

    </div>
</div>
<div>
    <div>

        <script type="text/javascript" src="/static/sb-admin-2/vendor/jquery/jquery.min.js"></script>

        <script type="text/javascript" src="/static/sb-admin-2/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>

        <!-- Core plugin JavaScript-->
        <script type="text/javascript" src="/static/sb-admin-2/vendor/jquery-easing/jquery.easing.min.js"></script>

        <!-- Custom scripts for all pages-->
        <script type="text/javascript" src="/static/sb-admin-2/js/sb-admin-2.min.js"></script>
        <script type="text/javascript" src="/static/jss/sweetalert-dev.js"></script>
    </div>
    <script type="text/javascript" src="/static/jss/jquery.preloader.min.js"></script>
    <script type="text/javascript" src="/static/jss/chosen.jquery.min.js"></script>
    <script type="text/javascript" src="/static/jss/split.min.js"></script>
    <script src="/static/sb-admin-2/bootstrap/bootstrap-table.min.js"></script>
    <script src="/static/sb-admin-2/bootstrap/bootstrap-table-zh-CN.js"></script>
    <script type="text/javascript" src="/static/jss/mjs/mjs_outpatient.js"></script>
    <script type="text/javascript" src="/static/jss/Print.js"></script>
</div>
</body>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/layui/layui.js"></script>
<script src="/static/sb-admin-2/vendor/jquery/jquery.min.js"></script>
<script>
         <!--方法-->
         <!--控制队列-->
         <!--页面加载获取方法的品和相应信息-->
         window.onload = function () {
             //获取所有医生下的队列
             refreshQueue();
             //获取所有药品
             getAllDrug();
         };

         //获取所有药品
         function getAllDrug() {
             layui.use(['form', 'laydate'], function () {
                 // layui引入需要的组件
                 var $ = layui.jquery;
                 var layer = layui.layer;
                 var form = layui.form;
                 // 二级联动 第一步 渲染父级
                 $.ajax({
                     url: '/drug/findAll',	// 后台取到所有的科室名称
                     dataType: 'json',
                     type: 'post',
                     success: function (resData) {
                         console.log(resData);
                         $.each(resData.data.list, function (index, value) {
                             console.log(value)
                             // 这里的 value.roomName
                             // 前者是页面显示的值，后者是传递给后台的值。
                             // 正常情况下，后者应该是 value.id
                             $('#drugSelect').append('<option value="' + value.name + '">' + value.name + '</option>');	// 下拉菜单里添加元素
                         });
                         //渲染select
                         form.render('select');
                     }
                 })
                 // 第二步 监听父级，每当父级发生变化时，渲染子级的值
                 form.on('select(drugSelect)', function (data) {
                     var name = data.value; // name 选中的科室名称
                     console.log(name)
                     $.ajax({
                         url: '/drug/findAll',
                         dataType: 'json',
                         type: 'post',
                         data: {name: name},		// 传入科室名称，查找该科室的所有床号
                         success: function (resData) {
                             console.log(data)
                             $.each(resData.data.list, function (index, value) {
                                 // 这里的 value.bedNo
                                 // 前者是页面显示的值，后者是传递给后台的值。
                                 // 正常情况下，后者应该是 value.id
                                 $("#specification").val(value.specification);
                                 $("#price").val(value.price)// 下拉菜单里添加元素
                             });
                             //渲染select
                             form.render('select');
                         }
                     });
                 });
             });
         }
         //添加药物
         /*处方药总价*/
         var allPrice = 0;
         function addDrugs() {
             var name = $("#drugSelect").val();
             var cardId = $("#cardId").val();
             var usage = $("#usage").val();
             var price = parseInt($("#price").val());
             var specification = $("#specification").val();
             //drug
             if (name == null || name === '') {
                 swal("请先选择药品！", "", "error");
                 return false;
             }
             if (usage == null || usage === '') {
                 swal("请填写药品每次剂量！", "", "error");
                 return false;
             }

             if (drugMethod == null || drugMethod === '') {
                 swal("请选择药品服用方式！", "", "error");
                 return false;
             }

             if (drugNum == null || drugNum === '') {
                 swal("请选择药品每日服用次数！", "", "error");
                 return false;
             }
             if (cardId == null || cardId === '') {
                 swal("请先读取就诊卡！", "", "error");
                 return false;
             }
             $("#drugs ol").append('<li>' + name + '<span style="margin-left:100px">'
                 + specification + '</span></li><div style="margin: 10px 0 10px 5px;">用法：<sapn>'
                 + usage + '</sapn><sapn  style="margin-left:40px">' + drugMethod
                 + '</sapn><sapn  style="margin-left:60px">' + drugNum + '</sapn></div>');
             allPrice = allPrice + price;
         }
         //清空药物
         function nullDrugs() {
             swal({
                 title: "添加的药品将全部清空，请确认操作！",
                 type: "info",
                 showCancelButton: true,
                 closeOnConfirm: true,
             }, function () {
                 $("#drugs ol").empty();
                 allPrice = 0;
             })

         }
         /*获取体检信息*/
         function findByIdMedicalExamination() {
             var prescriptionNum = $("#prescriptionNum").val();
             $.ajax({
                 url: "/medicalExamination/findById",
                 type: "post",
                 data: {
                     "medicalRecord.tolltakedrug_no": prescriptionNum
                 },
                 success: function (data) {
                     if (data.date.code == 200) {
                             $("#cardId").val(),
                             $("#bodyTemperature").val(data.date.body_temperature),
                             $("#pulse").val(data.date.pulse),
                             $("#heartRate").val(data.date.heart_rate),
                             $("#bloodPressure").val(data.date.blood_pressure),
                             $("#examinationCost").val(data.date.examination_cost)
                     } else {
                         swal(data.date.msg, "", "error")
                     }
                 }
             })
         }
         <!--查询卡号获取患者基础信息-->
        function getCardIdIn(command) {
           // var GetCardIdInforReqVO = {
               // command: command, //0:表示读卡器输入卡号 1:表示手动输入卡号
              var cardId = $("#cardId").val()
           // };
            $.ajax({
                url: "/patient/findByIdAll",
                type: "post",
                dataType: "json",
                data: {card_id:cardId},
                success: function (da) {
                    console.log(da);
                    if (da.code == 200) {
                        $("#cardId").val(da.date.card_id);
                        $("#name").val(da.date.name);
                        $("#sex").val(da.date.sex);
                        $("#nationality").val(da.date.nationality);
                        //da.date.age年龄时间计算
                        $("#age").val(da.date.age);
                        $("#prescriptionNum").val(da.date.medicalRecord.tolltakedrug_no);
                        $("#date").val(da.date.create_datetime);
                        $("#department").val(da.date.department.name);

                        if (da.date.marital_status == null || da.date.career == null || da.date.personal_history == null || da.date.past_history == null || da.date.family_history == null) {
                            $("#new-img").css("visibility", "visible");
                        }
                        $("#maritalstatus").val(da.date.marital_status);
                        $("#career").val(da.date.career);
                        $("#personalHistory").val(da.date.personal_history);
                        $("#pastHistory").val(da.date.past_history);
                        $("#familyHistory").val(da.date.family_history);

                       // $("#queueId").val(date.queueId);

                    } else {
                        swal(da.date.msg, "", "error")
                    }
                }
            })
        };
         //changePatientupdate提交修改信息
         function changePatientupdate() {
             var cardId = $("#cardId").val();
             if (cardId == null || cardId === '') {
                 swal("请先读取就诊卡！", "", "error");
                 return false;
             }
             var date = {
                 card_id: cardId,
                 marital_status: $("#marital_status").val(),
                 career: $("#career").val(),
                 personal_history: $("#personalHistory").val(),
                 past_history: $("#pastHistory").val(),
                 family_history: $("#familyHistory").val()
             };
             console.log(date)
             $.ajax({
                 url: "/hisPatient/update",
                 type: "post",
                 dataType: "json",
                 data: date,
                 success: function (data) {
                     //&& data.date.status === 1
                     if (data.code == 200) {
                         swal("信息提交成功！", "", "success")
                     } else {
                         swal(data.date.msg, "", "error")
                     }
                 }
             })
         };
         /*稍后处理*/
         function ProcessLater() {
             var name = $("#name").val();
             var card_id = $("#cardId").val();
             var prescriptionNum = $("#prescriptionNum").val();
             var queueId = $("#queueId").val();
             if (card_id == null || card_id === '') {
                 swal("请先读取就诊卡！", "", "error");
                 return false;
             }
             var date = {
                 card_id: cardId,
                 conditionDescription: $("#conditionDescr").val(),
                 prescriptionNum: prescriptionNum,
                 queueId: queueId

             };
             swal({
                     title: "稍后处理只会保存病历主诉信息，门诊体检需患者提供处方号，请确认您的操作！",
                     text: "<div id='printId'>姓名:<span style='color: #2C9FAF'>" + name + "</span>&emsp;卡号:<span style='color: #2C9FAF'>" + cardId + "</span>" +
                         "<br>处方号:<span style='color: #2C9FAF'>" + prescriptionNum + "</span></div><a class='mybutton-print' href='#' onclick='printPrescriptionNum()'>打印</a>",
                     html: true,
                     type: "info",
                     showCancelButton: true,
                     closeOnConfirm: false,
                     showLoaderOnConfirm: true

                 }, function () {
                     $.ajax({
                         url: "#",
                         type: "post",
                         dataType: "json",
                         data: date,
                         success: function (data) {
                             console.log(data)
                             //&& data.status === 1
                             if (data.code == 200) {
                                 setTimeout(function () {
                                     swal({
                                         title: "操作成功，如要恢复，请点击右侧栏进行操作",
                                         type: "success",
                                     }, function () {
                                         setTimeout(function () {
                                             window.location.reload()
                                         }, 500)
                                     });
                                 }, 1000)

                             } else {
                                 swal(data.date.msg, "", "error")
                             }
                         }
                     });


                 }
             );
         }
         //门诊完成
         function addMedicalRecord() {
             var name = $("#name").val();
             var cardId = $("#cardId").val();
             var diagnosisResult = $("#diagnosisResult").val();
             var medicalOrder = $("#medicalOrder").val();
             var queueId = $("#queueId").val();

             if (cardId == null || cardId === '') {
                 swal("请先读取就诊卡！", "", "error");
                 return false;
             }
             //drug
             if (name == null || name === '') {
                 swal("请选择药品！", "", "error");
                 return false;
             }
             if (diagnosisResult == null || diagnosisResult === '') {
                 swal("请填写初步诊断！", "", "error");
                 return false;
             }
             if (medicalOrder == null || medicalOrder === '') {
                 swal("请填写医嘱！", "", "error");
                 return false;
             }

             var date = {
                // cardId: cardId,
                 condition_description: $("#conditionDescr").val(),
                 prescription_num: $("#prescriptionNum").val(),
                 prescription: $("#drugs").html().trim(),
                 medical_order: medicalOrder,
               //  drugCost: allPrice,
                 diagnosis_result: diagnosisResult,
                // queueId: queueId
             };
             swal({
                 title: "请确认患者基本信息是否提交修改",
                 type: "info",
                 showCancelButton: true,
                 closeOnConfirm: false,
                 showLoaderOnConfirm: true
             }, function () {
                 setTimeout(function () {
                     $.ajax({
                         url: "/hisMedicalRecord/add",
                         type: "post",
                         dataType: "json",
                         data: date,
                         success: function (data) {
                             console.log(data)
                             //data !== null && data.status === 1
                             if (data.code == 200) {
                                 swal({
                                     title: "病历信息提交成功,本次就诊完成！",
                                     type: "success",
                                 }, function () {
                                     window.location.reload()
                                 });
                             } else {
                                 swal(data.date.msg, "", "error")
                             }
                         }
                     })

                 }, 1000)
             })
         }
</script>
</html>